package day14;
/*
* 自定义异常的使用
* */
public class Demo8 {
    public static void main(String[] args) {
        DemoPerson demoPerson = new DemoPerson();

        demoPerson.setAge(130);

        System.out.println(demoPerson.getAge());
    }
}
class DemoPerson{
    private String name;
    private int age;
    //get,set方法
    public void setAge(int age){
        if(age<0||age>120){
            throw new AgeException("整个正确的年龄");
        }else{
            this.age = age;
        }
    }

    public void setName(String name){
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }
}
